{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\BIS.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}31 Oct 2025, 09:17:34
{txt}
{com}. /* Define local and global variables */
> 
> local directory = "../../Data/BIS/Debt securities statistics";
{txt}
{com}. do global;
{txt}
{com}. /* global.do (STATA)
>         Define global variables in "Data".
>         by Ralph Koijen & Motohiro Yogo */
. 
. #delimit ;
{txt}delimiter now ;
{com}. clear all;
{res}{txt}
{com}. global year_min = 2003;
{txt}
{com}. global year_max = 2020;
{txt}
{com}. global small = 5e-4;
{txt}
{com}.         /* Minimum reportable threshold for CPIS */

{txt}end of do-file

{com}. /* Step 1: Construct domestic debt securities */
> 
> /* Load data */
> 
> u ISSUER_RES ISSUER_BUS_IMM market ISSUE_OR_MAT measure
>         _${c -(}year_min{c )-}_Q1-_${c -(}year_max{c )-}_Q4
>         if inlist(ISSUER_BUS_IMM,"2","B","J")   /* 2 = General government, B = Financial corporations, J = Nonfinancial coporations */
>         & market=="A"                                                   /* Domestic market */
>         & measure=="I"                                                  /* Amounts outstanding */
>         using "`directory'/WS_DEBT_SEC2_PUB_csv_col", clear;
{txt}
{com}. drop market measure;
{txt}
{com}. /* Rename variables */
> 
> rename ISSUER_RES ISO2;
{res}{txt}
{com}. rename ISSUER_BUS_IMM issuer;
{res}{txt}
{com}. foreach var of varlist *_Q* {c -(};
{txt}  2{com}.         rename `var' dds`=tq(`=substr("`var'",2,.)')';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. /* Merge country code */
> 
> merge m:1 ISO2 using Countries,
>         keepusing(Counterpart)
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}             199{txt}  
{col 5}{hline 41}

{com}. drop ISO2;
{txt}
{com}. /* Construct variables */
> 
> gen byte type = 0 if ISSUE_OR_MAT=="A";
{txt}(118 missing values generated)

{com}.         /* All debt */
> replace type = 1 if ISSUE_OR_MAT=="C";
{txt}(57 real changes made)

{com}.         /* ST debt */
> replace type = 2 if ISSUE_OR_MAT=="K";
{txt}(61 real changes made)

{com}.         /* LT debt */
> 
> drop ISSUE_OR_MAT;
{txt}
{com}. /* Reshape in long format */
> 
> reshape long dds, i(Counterpart issuer type) j(date);
{txt}(j = 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}         199   {txt}->   {res}14,328      
{txt}Number of variables        {res}          75   {txt}->   {res}5           
{txt}j variable (72 values)                    ->   {res}date
{txt}xij variables:
               {res}dds172 dds173 ... dds243   {txt}->   {res}dds
{txt}{hline 77}

{com}. /* Fix variables */
> 
> recode dds (0 = .);
{txt}(371 changes made to {bf:dds})

{com}. /* Expand to ST and LT debt */
> 
> sort date Counterpart issuer type;
{txt}
{com}. by date Counterpart issuer: gen byte obs = min(type[_n+1],3)-type;
{txt}
{com}. expand obs if obs==2, gen(duplicate);
{txt}(432 observations created)

{com}. replace type = type+1 if duplicate;
{txt}(432 real changes made)

{com}. replace dds = . if duplicate;
{txt}(386 real changes made, 386 to missing)

{com}. drop obs duplicate;
{txt}
{com}. /* Construct ratio between ST and LT debt */
> 
> sort date Counterpart issuer type;
{txt}
{com}. by date Counterpart issuer: gen ratio = dds/dds[_n+1] if type==1 & type[_n+1]==2;
{txt}(11,480 missing values generated)

{com}.                 /* ST to LT debt */
> by date Counterpart issuer: replace ratio = dds/dds[_n-1] if type==2 & type[_n-1]==1;
{txt}(3280 real changes made)

{com}.         /* LT to ST debt */
> 
> /* Extrapolate forward */
> 
> sort Counterpart issuer type date;
{txt}
{com}. by Counterpart issuer type: replace ratio = ratio[_n-1] if missing(ratio);
{txt}(438 real changes made)

{com}. /* Extrapolate backward */
> 
> gsort Counterpart issuer type -date;
{txt}
{com}. by Counterpart issuer type: replace ratio = ratio[_n-1] if missing(ratio);
{txt}(1066 real changes made)

{com}. /* Impute ST and LT debt based on their ratio at other dates */
> 
> sort date Counterpart issuer type;
{txt}
{com}. by date Counterpart issuer: replace dds = ratio*dds[_n+1] if type==1 & type[_n+1]==2 & missing(dds);
{txt}(315 real changes made)

{com}.         /* ST debt */
> by date Counterpart issuer: replace dds = ratio*dds[_n-1] if type==2 & type[_n-1]==1 & missing(dds);
{txt}(62 real changes made)

{com}.         /* LT debt */
> 
> drop ratio;
{txt}
{com}. /* Correct total */
> 
> egen Tdds = total(dds*(type!=0)), missing by(date Counterpart issuer);
{txt}(1,154 missing values generated)

{com}. replace dds = Tdds if type==0 & Tdds>0;
{txt}(1,390 real changes made)

{com}. drop Tdds;
{txt}
{com}. /* Keep year-end data */
> 
> gen int year = year(dofq(date));
{txt}
{com}. keep if quarter(dofq(date))==4;
{txt}(11,070 observations deleted)

{com}. drop date;
{txt}
{com}. /* Aggregate across issuers */
> 
> collapse (sum) dds, by(year Counterpart type) fast;
{res}{txt}
{com}. /* Impute ST and LT debt from All debt */
> 
> egen dds0 = total(dds*(type==0)), missing by(year Counterpart);
{txt}
{com}. egen Tdds = total(dds*(type!=0)), missing by(year Counterpart);
{txt}
{com}. replace dds = dds0*dds/Tdds if type!=0;
{txt}(228 real changes made, 90 to missing)

{com}. drop dds0 Tdds;
{txt}
{com}. /* Construct variables */
> 
> gen currency = "ALL";
{txt}
{com}. /* Save data */
> 
> tempfile DDS;
{txt}
{com}. save `DDS';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_9840_000001.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 2: Construct total debt securities */
> 
> /* Load data */
> 
> u ISSUER_RES ISSUER_BUS_IMM market measure
>         _${c -(}year_min{c )-}_Q4-_${c -(}year_max{c )-}_Q4
>         if ISSUER_BUS_IMM=="1"  /* All issuers */
>         & market=="1"                   /* All markets */
>         & measure=="I"                  /* Amounts outstanding */
>         using "`directory'/WS_DEBT_SEC2_PUB_csv_col", clear;
{txt}
{com}. drop ISSUER_BUS_IMM market measure *_Q1 *_Q2 *_Q3;
{txt}
{com}. /* Rename variables */
> 
> rename ISSUER_RES ISO2;
{res}{txt}
{com}. foreach var of varlist *_Q4 {c -(};
{txt}  2{com}.         rename `var' tds`=substr("`var'",2,4)';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. /* Merge country code */
> 
> merge m:1 ISO2 using Countries,
>         keepusing(Counterpart)
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}              44{txt}  
{col 5}{hline 41}

{com}. drop ISO2;
{txt}
{com}. /* Reshape in long format */
> 
> reshape long tds, i(Counterpart) j(year);
{txt}(j = 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}          44   {txt}->   {res}792         
{txt}Number of variables        {res}          19   {txt}->   {res}3           
{txt}j variable (18 values)                    ->   {res}year
{txt}xij variables:
            {res}tds2003 tds2004 ... tds2020   {txt}->   {res}tds
{txt}{hline 77}

{com}. drop if missing(tds);
{txt}(35 observations deleted)

{com}. /* Construct variables */
> 
> gen byte type = 0;
{txt}
{com}. gen currency = "ALL";
{txt}
{com}. /* Save data */
> 
> tempfile TDS;
{txt}
{com}. save `TDS';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_9840_000002.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 3: Construct international debt securities */
> 
> /* Load data */
> 
> u ISSUER_RES ISSUER_NAT ISSUER_BUS_IMM ISSUER_BUS_ULT market
>         ISSUE_CUR_GROUP ISSUE_CUR ISSUE_OR_MAT ISSUE_RE_MAT ISSUE_RATE measure
>         _${c -(}year_min{c )-}_Q4-_${c -(}year_max{c )-}_Q4
>         if ISSUER_NAT=="3P"                                                                             /* All countries excluding residents */
>         & ISSUER_BUS_IMM=="1"                                                                   /* All issuers */
>         & ISSUER_BUS_ULT=="1"                                                                   /* All issuers */
>         & market=="C"                                                                                   /* International markets */
>         & (inlist(ISSUE_CUR_GROUP,"A","D") & ISSUE_CUR=="TO1"   /* A = All currencies, D = Domestic currency, F = Foreign currencies */
>         | ISSUE_CUR_GROUP=="F")
>         & ISSUE_RE_MAT=="A"                                                                             /* All remaining maturities */
>         & ISSUE_RATE=="A"                                                                               /* All rate types */
>         & measure=="I"                                                                                  /* Amounts outstanding */
>         using "`directory'/WS_DEBT_SEC2_PUB_csv_col", clear;
{txt}
{com}. drop ISSUER_NAT ISSUER_BUS_IMM ISSUER_BUS_ULT market ISSUE_RE_MAT ISSUE_RATE measure *_Q1 *_Q2 *_Q3;
{txt}
{com}. /* Rename variables */
> 
> rename ISSUER_RES ISO2;
{res}{txt}
{com}. foreach var of varlist *_Q4 {c -(};
{txt}  2{com}.         rename `var' ids`=substr("`var'",2,4)';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. /* Merge country code */
> 
> merge m:1 ISO2 using Countries,
>         keepusing(Counterpart Yeuro)
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           1,602{txt}  
{col 5}{hline 41}

{com}. drop ISO2;
{txt}
{com}. /* Construct variables */
> 
> gen byte type = 0 if ISSUE_OR_MAT=="A";
{txt}(973 missing values generated)

{com}.         /* All debt */
> replace type = 1 if ISSUE_OR_MAT=="C";
{txt}(353 real changes made)

{com}.         /* ST debt */
> replace type = 2 if ISSUE_OR_MAT=="K";
{txt}(620 real changes made)

{com}.         /* LT debt */
> 
> drop ISSUE_OR_MAT;
{txt}
{com}. /* Reshape in long format */
> 
> reshape long ids, i(Counterpart type ISSUE_CUR_GROUP ISSUE_CUR) j(year);
{txt}(j = 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}       1,602   {txt}->   {res}28,836      
{txt}Number of variables        {res}          23   {txt}->   {res}7           
{txt}j variable (18 values)                    ->   {res}year
{txt}xij variables:
            {res}ids2003 ids2004 ... ids2020   {txt}->   {res}ids
{txt}{hline 77}

{com}. /* Fix variables */
> 
> recode ids (. = 0);
{txt}(9,376 changes made to {bf:ids})

{com}. /* Construct currency */
> 
> gen currency = "ALL" if ISSUE_CUR_GROUP=="A";
{txt}(21,636 missing values generated)

{com}.                                                         /* All currencies */
> replace currency = Counterpart if ISSUE_CUR_GROUP=="D" & year<Yeuro;
{txt}(2,634 real changes made)

{com}.         /* Domestic currency */
> replace currency = "EUR" if ISSUE_CUR_GROUP=="D" & year>=Yeuro;
{txt}(804 real changes made)

{com}. replace currency = "EUR" if ISSUE_CUR_GROUP=="F" & ISSUE_CUR=="EU1";
{txt}(4,464 real changes made)

{com}.         /* Euro */
> replace currency = "USA" if ISSUE_CUR_GROUP=="F" & ISSUE_CUR=="USD";
{txt}(6,606 real changes made)

{com}.         /* US dollar */
> 
> drop if ISSUE_CUR_GROUP=="F" & ISSUE_CUR=="EU1" & year>=Yeuro;
{txt}(602 observations deleted)

{com}. drop Yeuro;
{txt}
{com}. /* Construct other foreign currencies */
> 
> egen Tids = total(ids*(ISSUE_CUR!="TO1")) if ISSUE_CUR_GROUP=="F", missing by(year Counterpart type);
{txt}(10,638 missing values generated)

{com}. replace currency = "_OC" if ISSUE_CUR_GROUP=="F" & ISSUE_CUR=="TO1";
{txt}(7,128 real changes made)

{com}. replace ids = max(ids-Tids,0) if ISSUE_CUR_GROUP=="F" & ISSUE_CUR=="TO1";
{txt}(4,860 real changes made)

{com}. drop ISSUE_CUR_GROUP ISSUE_CUR Tids;
{txt}
{com}. /* Correct rounding error in total */
> 
> egen Tids = total(ids*(currency!="ALL")), missing by(year Counterpart type);
{txt}
{com}. replace ids = Tids if currency=="ALL";
{txt}(581 real changes made)

{com}. drop Tids;
{txt}
{com}. /* Save data */
> 
> tempfile IDS;
{txt}
{com}. save `IDS';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_9840_000003.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 4: Construct debt outstanding */
> 
> /* Load domestic debt securities */
> 
> u `DDS', clear;
{txt}
{com}. /* Merge total debt securities */
> 
> merge 1:1 year Counterpart type currency using `TDS',
>         nogen;
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}           1,699
{txt}{col 9}from master{col 30}{res}           1,245{txt}  
{col 9}from using{col 30}{res}             454{txt}  

{col 5}Matched{col 30}{res}             303{txt}  
{col 5}{hline 41}

{com}. /* Merge international debt securities */
> 
> merge 1:1 year Counterpart type currency using `IDS',
>         nogen;
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}          26,268
{txt}{col 9}from master{col 30}{res}              18{txt}  
{col 9}from using{col 30}{res}          26,250{txt}  

{col 5}Matched{col 30}{res}           1,984{txt}  
{col 5}{hline 41}

{com}. /* Merge country code */
> 
> merge m:1 Counterpart using Countries,
>         keepusing(Ynat Idds Itds)
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}          28,252{txt}  
{col 5}{hline 41}

{com}. /* Keep sample of countries */
> 
> keep if year>=Ynat;
{txt}(19,462 observations deleted)

{com}. drop Ynat;
{txt}
{com}. /* Update missing domestic debt securities */
> 
> replace Idds = 0 if missing(dds) & !missing(tds) & Itds==0;
{txt}(231 real changes made)

{com}. replace dds = max(tds-ids,0) if missing(dds) & !missing(tds) & Itds==0;
{txt}(231 real changes made)

{com}. drop tds Itds;
{txt}
{com}. /* Convert to US$ billion */
> 
> foreach var of varlist dds ids {c -(};
{txt}  2{com}.         replace `var' = `var'/1e3;
{txt}  3{com}. {c )-};
{txt}(1,222 real changes made)
(7,664 real changes made)

{com}. /* Merge market-to-book value */
> 
> merge m:1 year Counterpart type using Data1,
>         keepusing(mb)
>         nogen keep(master match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}           3,002
{txt}{col 9}from master{col 30}{res}           3,002{txt}  
{col 9}from using{col 30}{res}               0{txt}  

{col 5}Matched{col 30}{res}           5,788{txt}  
{col 5}{hline 41}

{com}. /* Convert book value to market value */
> 
> replace dds = dds*mb if type!=0 & Idds==0;
{txt}(499 real changes made)

{com}. replace ids = ids*mb if type!=0;
{txt}(4,755 real changes made)

{com}. drop Idds mb;
{txt}
{com}. /* Correct total */
> 
> foreach var of varlist dds ids {c -(};
{txt}  2{com}.         egen T`var' = total(`var'*(type!=0)) if currency=="ALL", missing by(year Counterpart);
{txt}  3{com}.         replace `var' = T`var' if type==0 & currency=="ALL" & T`var'>0;
{txt}  4{com}.         drop T`var';
{txt}  5{com}. {c )-};
{txt}(6,987 missing values generated)
(269 real changes made)
(6,870 missing values generated)
(640 real changes made)

{com}. /* Label variables */
> 
> order year Counterpart type currency;
{txt}
{com}. label var year          "Year";
{txt}
{com}. label var type          "Asset type";
{txt}
{com}. label var currency      "Currency";
{txt}
{com}. label var dds           "Domestic debt securities (US$ billion)";
{txt}
{com}. label var ids           "International debt securities (US$ billion)";
{txt}
{com}. label define type_label
>         0 "All debt"
>         1 "Short-term debt"
>         2 "Long-term debt", replace;
{txt}
{com}. label val type type_label;
{txt}
{com}. /* Save data */
> 
> sort year Counterpart type currency;
{txt}
{com}. save BIS, replace;
{txt}{p 0 4 2}
file {bf}
BIS.dta{rm}
saved
{p_end}

{com}. log close;
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\BIS.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}31 Oct 2025, 09:17:37
{txt}{.-}
{smcl}
{txt}{sf}{ul off}